﻿using System.Collections.Generic;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Data;
using System.Linq;

namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        /// <summary>
        /// GetJob is used to collect the tasks to finish the order creation
        /// </summary>
        /// <param name="FInterID"></param>
        /// <returns></returns>
        public void SJQIPRA(DataSet db)
        {
            try
            {
                DataTable tbWBBST = db.Tables["ICC_STOCK"];
                DataTable dtOutput = new DataTable();
                int idx = 1;
                int x = 3;
                #region======Title===========
                exAgent.SetCellValue(x, idx++, "时间区段"); dtOutput.Columns.Add("TIMERANGE", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "生产日期"); dtOutput.Columns.Add("WBEWBUCHDAT", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "品名"); dtOutput.Columns.Add("WABEZ", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "批号"); dtOutput.Columns.Add("ABPARTEX", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "品种"); dtOutput.Columns.Add("WAART", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷A"); dtOutput.Columns.Add("STKNRSA", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "数A"); dtOutput.Columns.Add("QYTA", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "A级率%"); dtOutput.Columns.Add("RATIOA", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷B"); dtOutput.Columns.Add("STKNRSB", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "数B"); dtOutput.Columns.Add("QYTB", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "B级率%"); dtOutput.Columns.Add("RATIOB", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷C"); dtOutput.Columns.Add("STKNRSC", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "数C"); dtOutput.Columns.Add("QYTC", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "C级率%"); dtOutput.Columns.Add("RATIOC", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷数"); dtOutput.Columns.Add("STKNRST", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "总米数"); dtOutput.Columns.Add("QTYT", typeof(System.String));
                #endregion
               
                dtOutput.Merge(tbWBBST, false, MissingSchemaAction.Ignore);
                string title = "";
                foreach (DataRow row in dtOutput.Rows)
                {
                    title = "每日A级率" + row["TIMERANGE"].ToString();
                    row["WAART"] = Helpers.Helper.GetGB2312Value(row["WAART"].ToString().Trim());
                    row["WABEZ"] = Helpers.Helper.GetGB2312Value(row["WABEZ"].ToString().Trim());
                    row["ABPARTEX"] = Helpers.Helper.GetGB2312Value(row["ABPARTEX"].ToString().Trim());

                }
                exAgent.DataTableToExcel(dtOutput, x + 1, 1);
                exAgent.SetCellValue(1, 1, "每日A级率");
                int count = dtOutput.Rows.Count;
                exAgent.BatchConvert2Number(x, 6, count + x, 16);
                exAgent.SetCellValue(1, 2, title);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


    }
}
